package com.ruoyi.web.controller.app;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.TRealm;
import com.ruoyi.system.domain.TWorkOrder;
import com.ruoyi.system.service.ICensusService;
import com.ruoyi.system.service.ITRealmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.YearMonth;
import java.util.List;

/**
 * 数据分析
 */
@RestController
@RequestMapping("/system/census")
public class CensusController extends BaseController {

    @Autowired
    private ICensusService iCensusService;
    @Autowired
    private ITRealmService itRealmService;

    /**
     * 系统综合数据
     */
    @GetMapping("/groupList")
    public AjaxResult groupList(){
        return AjaxResult.success(iCensusService.groupList(checkAdmin()));
    }

    /**
     * 个人工单列表（超管除外）
     */
    @GetMapping("/works")
    public TableDataInfo works(TWorkOrder tWorkOrder){
        startPage();
        if (!checkAuth()) tWorkOrder.setUid(getUserId());
        List<TWorkOrder> list = iCensusService.works(tWorkOrder);
        return getDataTable(list);
    }

    /**
     * 日访问量折线图（包含有效访问）
     */
    @PostMapping("/accessOfDay/{id}")
    public AjaxResult accessOfDay(@PathVariable Long id){
        return AjaxResult.success(iCensusService.accessOfDay(id));
    }
    /**
     * 月访问量折线图（包含有效访问）
     */
    @PostMapping("/accessOfMonth/{id}")
    public AjaxResult accessOfMonth(@PathVariable Long id){
        return AjaxResult.success(iCensusService.accessOfMonth(id));
    }

    @GetMapping("/getRealmList")
    public AjaxResult getRealmList(){
        JSONObject json = new JSONObject();
        List<TRealm> list = itRealmService.selectTRealmList(new TRealm());
        json.put("list",list);
        json.put("url",list.isEmpty() ? "" : list.get(0).getUrl());
        return AjaxResult.success(json);
    }



}
